package com.gorkr;

import org.junit.jupiter.api.Test;

/**
 * @author gorkr
 * @date 2022/01/18 09:51
 **/
public class J21 {

    public int[] exchange(int[] nums) {
        int left = 0, right = nums.length-1;
        int tmp;
        while(left<right){
            while(left<right&&nums[left]%2==1){
                left++;
            }
            while(left<right&&nums[right]%2==0){
                right--;
            }
            tmp = nums[left];
            nums[left] = nums[right];
            nums[right] = tmp;
        }
        return nums;
    }

    @Test
    public void test(){
        int[] nums = {1, 2, 3, 4};
        System.out.println(exchange(nums));
    }

}
    